package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Training;
import cn.wolfcode.crm.service.ITrainingService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("training")
@Controller
public class TrainingController {


    @Autowired
    private ITrainingService trainingService;

    @RequestMapping("view")
    public String list() {
        return "/employeeinfo/training";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Training entity){
        JSONResult result = new JSONResult();
        try {
            trainingService.saveOrUpdate(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
    @RequestMapping("selectAll")
    @ResponseBody
    public List<Training> selectAll() {
        return trainingService.selectAll();
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object delete(Long id) {
        trainingService.delete(id);

        return new JSONResult();
    }

}



